import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AdmAssetStoreVO, AdmAssetStoreForm, AdmAssetStoreQuery } from '@/api/general/administration/asset/store/types';

/**
 * 查询资产入库登记列表
 * @param query
 * @returns {*}
 */

export const listAdmAssetStore = (query?: AdmAssetStoreQuery): AxiosPromise<AdmAssetStoreVO[]> => {
  return request({
    url: '/system/admAssetStore/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询资产入库登记详细
 * @param id
 */
export const getAdmAssetStore = (id: string | number): AxiosPromise<AdmAssetStoreVO> => {
  return request({
    url: '/system/admAssetStore/' + id,
    method: 'get'
  });
};

/**
 * 新增资产入库登记
 * @param data
 */
export const addAdmAssetStore = (data: AdmAssetStoreForm) => {
  return request({
    url: '/system/admAssetStore',
    method: 'post',
    data: data
  });
};

/**
 * 修改资产入库登记
 * @param data
 */
export const updateAdmAssetStore = (data: AdmAssetStoreForm) => {
  return request({
    url: '/system/admAssetStore',
    method: 'put',
    data: data
  });
};

/**
 * 删除资产入库登记
 * @param id
 */
export const delAdmAssetStore = (id: string | number | Array<string | number>) => {
  return request({
    url: '/system/admAssetStore/' + id,
    method: 'delete'
  });
};

/**
 * 导入物品 Excel
 * @param file 文件对象
 * @param bookStoreBo 额外参数对象
 */
export const importAsset = (file: File, bookStoreBo: AdmAssetStoreForm): AxiosPromise<void> => {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('data', JSON.stringify(bookStoreBo));

  return request({
    url: '/system/admAssetStore/import',
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  });
};